package com.liuzh.deviceinfo.view.togglebuttongroup;

import android.content.Context;
import android.content.res.TypedArray;
import android.util.AttributeSet;
import android.view.View;
import android.view.ViewGroup.OnHierarchyChangeListener;
import android.widget.Checkable;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import c.h.a.q;
import java.util.Objects;

public abstract class ToggleButtonGroup extends FlowLayout {
    public static final /* synthetic */ int o = 0;
    public int j;
    public int k;
    public c.h.a.n0.j.a l;
    public OnCheckedChangeListener m;
    public d n;

    public class c implements OnCheckedChangeListener {
        public c(a aVar) {
        }

        public void onCheckedChanged(CompoundButton compoundButton, boolean z) {
            ToggleButtonGroup.this.f(compoundButton, z);
        }
    }

    public class d implements OnHierarchyChangeListener {
        public OnHierarchyChangeListener a;

        public d(a aVar) {
        }

        public void onChildViewAdded(View view, View view2) {
            if (view == ToggleButtonGroup.this && (view2 instanceof Checkable)) {
                if (view2.getId() == -1) {
                    view2.setId(View.generateViewId());
                }
                if (view2 instanceof c.h.a.n0.j.b.b) {
                    ToggleButtonGroup.this.setStateTracker((c.h.a.n0.j.b.b) view2);
                } else if (view2 instanceof CompoundButton) {
                    ToggleButtonGroup.this.setStateTracker((CompoundButton) view2);
                }
            }
            OnHierarchyChangeListener onHierarchyChangeListener = this.a;
            if (onHierarchyChangeListener != null) {
                onHierarchyChangeListener.onChildViewAdded(view, view2);
            }
        }

        public void onChildViewRemoved(View view, View view2) {
            View view3 = ToggleButtonGroup.this;
            if (view == view3 && (view2 instanceof Checkable)) {
                int i;
                if (view2 instanceof c.h.a.n0.j.b.b) {
                    c.h.a.n0.j.b.b bVar = (c.h.a.n0.j.b.b) view2;
                    i = ToggleButtonGroup.o;
                    Objects.requireNonNull(view3);
                    bVar.setOnCheckedChangeListener(null);
                } else if (view2 instanceof CompoundButton) {
                    CompoundButton compoundButton = (CompoundButton) view2;
                    i = ToggleButtonGroup.o;
                    Objects.requireNonNull(view3);
                    compoundButton.setOnCheckedChangeListener(null);
                }
            }
            OnHierarchyChangeListener onHierarchyChangeListener = this.a;
            if (onHierarchyChangeListener != null) {
                onHierarchyChangeListener.onChildViewRemoved(view, view2);
            }
        }
    }

    public class b implements c.h.a.n0.j.a {
        public b(a aVar) {
        }
    }

    public ToggleButtonGroup(Context context, AttributeSet attributeSet) {
        super(context, attributeSet);
        TypedArray obtainStyledAttributes = context.getTheme().obtainStyledAttributes(attributeSet, q.f, 0, 0);
        try {
            this.j = obtainStyledAttributes.getResourceId(1, -1);
            this.k = obtainStyledAttributes.getResourceId(0, -1);
            d dVar = new d(null);
            this.n = dVar;
            super.setOnHierarchyChangeListener(dVar);
        } finally {
            obtainStyledAttributes.recycle();
        }
    }

    /* access modifiers changed from: private */
    public void setStateTracker(c.h.a.n0.j.b.b bVar) {
        if (this.l == null) {
            this.l = new b(null);
        }
        bVar.setOnCheckedChangeListener(this.l);
    }

    public abstract <T extends View & Checkable> void f(T t, boolean z);

    public void g(int i, boolean z) {
        View findViewById = findViewById(i);
        if (findViewById instanceof Checkable) {
            ((Checkable) findViewById).setChecked(z);
        }
    }

    public void setOnHierarchyChangeListener(OnHierarchyChangeListener onHierarchyChangeListener) {
        this.n.a = onHierarchyChangeListener;
    }

    /* access modifiers changed from: private */
    public void setStateTracker(CompoundButton compoundButton) {
        if (this.m == null) {
            this.m = new c(null);
        }
        compoundButton.setOnCheckedChangeListener(this.m);
    }
}
